import {
  mysqlTable,
  mysqlSchema,
  AnyMySqlColumn,
  primaryKey,
  unique,
  bigint,
  varchar,
  int,
  tinyint,
  timestamp,
  smallint,
  decimal,
} from 'drizzle-orm/mysql-core';
import { sql } from 'drizzle-orm';

export const lucky_area_store_food = mysqlTable(
  'lucky_area_store_food',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    food_id: bigint('food_id', { mode: 'number' }).notNull(),
    store_id: bigint('store_id', { mode: 'number' }),
  },
  (table) => {
    return {
      lucky_area_store_food_id: primaryKey({
        columns: [table.id],
        name: 'lucky_area_store_food_id',
      }),
      lucky_area_store_food_id_uindex: unique(
        'lucky_area_store_food_id_uindex',
      ).on(table.id),
    };
  },
);

export const lucky_food = mysqlTable(
  'lucky_food',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    name: varchar('name', { length: 10 }).notNull(),
    description: varchar('description', { length: 30 }),
    imgs: varchar('imgs', { length: 100 }),
    originPrice: int('originPrice').notNull(),
    groupId: bigint('groupId', { mode: 'number' }),
    active: tinyint('active').default(1).notNull(),
    is_standard: tinyint('is_standard').default(1),
  },
  (table) => {
    return {
      lucky_food_id: primaryKey({ columns: [table.id], name: 'lucky_food_id' }),
      lucky_food_id_uindex: unique('lucky_food_id_uindex').on(table.id),
    };
  },
);

export const lucky_food_group = mysqlTable(
  'lucky_food_group',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    pid: bigint('pid', { mode: 'number' }),
    name: varchar('name', { length: 10 }).notNull(),
    description: varchar('description', { length: 50 }),
  },
  (table) => {
    return {
      lucky_food_group_id: primaryKey({
        columns: [table.id],
        name: 'lucky_food_group_id',
      }),
      table_name_id_uindex: unique('table_name_id_uindex').on(table.id),
    };
  },
);

export const lucky_order = mysqlTable(
  'lucky_order',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    name: varchar('name', { length: 50 }).notNull(),
    create_time: timestamp('create_time', { mode: 'string' }),
    pay_time: timestamp('pay_time', { mode: 'string' }),
    close_time: timestamp('close_time', { mode: 'string' }),
    buy_way: smallint('buy_way'),
    send_time: timestamp('send_time', { mode: 'string' }),
    order_status: smallint('order_status').notNull(),
    total_price: int('total_price').notNull(),
  },
  (table) => {
    return {
      lucky_order_id: primaryKey({
        columns: [table.id],
        name: 'lucky_order_id',
      }),
      lucky_food_order_id_uindex: unique('lucky_food_order_id_uindex').on(
        table.id,
      ),
    };
  },
);

export const lucky_order_food = mysqlTable(
  'lucky_order_food',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    food_id: bigint('food_id', { mode: 'number' }).notNull(),
    order_id: int('order_id').notNull(),
    buy_number: int('buy_number'),
  },
  (table) => {
    return {
      lucky_order_food_id: primaryKey({
        columns: [table.id],
        name: 'lucky_order_food_id',
      }),
      lucky_order_food_id_uindex: unique('lucky_order_food_id_uindex').on(
        table.id,
      ),
    };
  },
);

export const lucky_store = mysqlTable(
  'lucky_store',
  {
    id: bigint('id', { mode: 'number', unsigned: true })
      .autoincrement()
      .notNull(),
    name: varchar('name', { length: 50 }).notNull(),
    address: varchar('address', { length: 100 }),
    longitude: decimal('longitude', { precision: 6, scale: 3 }).notNull(),
    latitude: decimal('latitude', { precision: 6, scale: 3 }).notNull(),
  },
  (table) => {
    return {
      lucky_store_id: primaryKey({
        columns: [table.id],
        name: 'lucky_store_id',
      }),
    };
  },
);

export const lucky_test = mysqlTable(
  'lucky_test',
  {
    id: int('id').autoincrement().notNull(),
    name: varchar('name', { length: 255 }).notNull(),
    test_int: int('test_int'),
  },
  (table) => {
    return {
      lucky_test_id: primaryKey({ columns: [table.id], name: 'lucky_test_id' }),
    };
  },
);

export const lucky_user = mysqlTable(
  'lucky_user',
  {
    id: bigint('id', { mode: 'number' }).autoincrement().notNull(),
    name: varchar('name', { length: 10 }).notNull(),
  },
  (table) => {
    return {
      lucky_user_id: primaryKey({ columns: [table.id], name: 'lucky_user_id' }),
      lucky_user_id_uindex: unique('lucky_user_id_uindex').on(table.id),
    };
  },
);
